package com.film.admincontroller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.film.domain.User;
import com.film.service.UserService;
import com.film.service.impl.UserServiceImpl;

@WebServlet("/userShow.do")
public class UserShowAdminController extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		HttpSession session = req.getSession();
		UserService userService = new UserServiceImpl();
		String uId = req.getParameter("id");
		if(uId!=null) {
			System.out.println("进来了");
			deleteUser(Integer.parseInt(uId), req, resp);
		}
		List<User> userList= userService.selectALl();
		session.setAttribute("userList", userList);
		resp.sendRedirect("/film/UserTypePage.do?page=1");
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req,resp);
	}
	
	public void deleteUser(Integer uId,HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		UserService userService = new UserServiceImpl();
		if(userService.deleteUser(uId)==0) {
			System.out.println("删除失败");
		}else {
			System.out.println("删除成功");
		}
	}
}
